package demo1;

public class test {

        //计算冒泡排序的时间复杂度

        void bubbleSort(int[] array) {
            int n = array.length;
            boolean swapped;
            for(int i = 0;i < n-1;i++){
                swapped = false;
                for(int j = 0;j < n - i -j;j++){
                    if (array[j] > array[j+1]) {
                        int temp = array[j];
                        array[j] = array[j+1];
                        array[j+1] = temp;
                        swapped = true;
                    }
                }
                if(!swapped){
                    break;
                }
            }


            //计算binarySearch的时间复杂度
    /*int binarySearch(int[] array, int value) {
        int left = 0;
        int right = array.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (array[mid] == value) {
                return mid;
            } else if (array[mid] > value) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }*/

            //计算斐波那契数列的时间复杂度
    /*int fibonacci(int N){
        return N < 2 ? N : fibonacci(N-1)+fibonacci(N-2);
    }*/

            //计算阶乘递归的时间复杂度
    /*int factorial(int N) {
        return N < 2 ? N : factorial(N - 1) * N;
    }*/

            // 计算fibonacci的空间复杂度
    /*long [] fibonacci(int n) {
        long[] fibArray = new long[n + 1];
        fibArray[0] = 0;
        fibArray[1] = 1;
        for (int i = 2; i <= n; i++) {
            fibArray[i] = fibArray[i - 1] + fibArray[i - 2];
        }
        return fibArray;
    }*/
        }
    }



